//
//  HBInvestSuccessCtrl.m
//  HuoBao
//
//  Created by 于会海 on 15/11/30.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "HBInvestSuccessCtrl.h"
#import "RecordViewCtrl.h"
#import "UIImageView+WebCache.h"
#import "HBSetTradpasswordCtrl.h"
#import "HBTabBarViewController.h"

@interface HBInvestSuccessCtrl ()
{
    UIView* line[5];
}
@property (weak, nonatomic) IBOutlet UIView *topView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topViewHeight;
- (IBAction)buttonClicked:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UIButton *recodeBtn;
@property (weak, nonatomic) IBOutlet UIButton *backHomeBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topViewW;
@property (weak, nonatomic) IBOutlet UILabel *topTitle;
@property (weak, nonatomic) IBOutlet UILabel *topDetail;
@property (weak, nonatomic) IBOutlet UILabel *firLabel;
@property (weak, nonatomic) IBOutlet UILabel *tradLabel;
@property (weak, nonatomic) IBOutlet UILabel *InterestDate;

@property (weak, nonatomic) IBOutlet UIImageView *bankCodeImageView;
@property (weak, nonatomic) IBOutlet UILabel *bankNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *inverestDateLabel;
@property (weak, nonatomic) IBOutlet UILabel *investTimeLabel;
@property (weak, nonatomic) IBOutlet UILabel *investMoney;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *botBtnVerToView;

@end

@implementation HBInvestSuccessCtrl

#define GetIPhone4or5result(a,b) (isIphone4or5?a:b)
- (void)viewDidLoad {
    [super viewDidLoad];
     CGFloat YHeight = 44;
    for (int i=0; i<5; i++) {
        line[i] = [[UIView alloc] initWithFrame:CGRectMake(0,self.topViewHeight.constant/2 -GetIPhone4or5result(22, 13), SCREEN_WIDTH-30, 0.5)];
        [line[i] setBackgroundColor:[LCCommon getColor:@"585858"]];
        line[i].frame = CGRectOffset(line[i].frame, 15, YHeight);
        [self.view addSubview:line[i]];
        YHeight += 44 + line[i].frame.size.height;
    }
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)buildLayout{
    self.title = @"申请成功";
    [[NSNotificationCenter defaultCenter]postNotificationName:@"upIncomeData" object:nil];
    if (IsIphone4) {
        self.botBtnVerToView.constant = 20;
    }
    if (isIphone4or5) {
        self.topViewHeight.constant = 90;
    }else{
        self.topViewHeight.constant = 100;
    }
    if (self.confirmInvestInfo) {
        [self.bankCodeImageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",self.confirmInvestInfo.bankCode]]];
        self.investMoney.text = self.confirmInvestInfo.investMoney;
        self.investTimeLabel.text = self.confirmInvestInfo.investTime;
        self.inverestDateLabel.text = self.confirmInvestInfo.interestDate;
        self.bankNameLabel.text = [NSString stringWithFormat:@"%@(%@)",self.confirmInvestInfo.bankName,self.confirmInvestInfo.bankCardShort];
    }
    if (self.confirmDistillInfo) {
        self.topViewW.constant = 290;
        self.topTitle.text = @"提现申请成功";
        self.topDetail.text = @"正在努力确认中，48小时之内到账";
        self.firLabel.text = @"提现金额";
        self.tradLabel.text = @"交易时间";
        self.investTimeLabel.text = @"结束计息";
        
        
        [self.bankCodeImageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",self.confirmDistillInfo.bankCode]]];
        self.investMoney.text = self.confirmDistillInfo.distillMoney;
        self.investTimeLabel.text = self.confirmDistillInfo.distillTime;
        self.inverestDateLabel.text = self.confirmDistillInfo.interestDate;
        self.bankNameLabel.text = [NSString stringWithFormat:@"%@(%@)",self.confirmDistillInfo.bankName,self.confirmDistillInfo.bankCardShort];
        [self.view layoutIfNeeded];
    }
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    self.recodeBtn.layer.masksToBounds = YES;
    self.backHomeBtn.layer.masksToBounds = YES;
    self.recodeBtn.layer.cornerRadius = 4;
    self.backHomeBtn.layer.cornerRadius = 4;
    [self.recodeBtn setBackgroundColor:[LCCommon getColor:@"38393f"] forState:UIControlStateHighlighted];
    [self.backHomeBtn setBackgroundColor:[LCCommon getColor:@"d43333"] forState:UIControlStateHighlighted];
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    if (self.navigationController.viewControllers[0] != self) {
        self.navigationItem.leftBarButtonItem = leftItem;
    }
}


- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)doBack{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (IBAction)buttonClicked:(UIButton *)sender {
    if (sender.tag == 2000) {
        HBTabBarViewController *tab = [[HBTabBarViewController alloc]init];
        tab.selectedIndex = 0;
        [UIApplication sharedApplication].keyWindow.rootViewController = tab;
        
    }else if(sender.tag == 2001){
        LLog(@"查看交易记录");
        RecordViewCtrl* recordVC = [[RecordViewCtrl alloc] init];
       // recordVC.currentMoney =  [NSString stringWithFormat:@"%.2f",[self.confirmInvestInfo.currentMoney doubleValue]];
        [self.navigationController pushViewController:recordVC animated:YES];
    }
}

@end
